let path = require("path");
let HtmlWebpackPlugin = require("html-webpack-plugin");
let MiniCssExtractPlugin = require("mini-css-extract-plugin");
let webpack = require("webpack");
const DllReferencePlugin = require('webpack/lib/DllReferencePlugin');
module.exports = {
  mode: "development", // 模式 默认两种 production development
  entry: "./src/index.js", // 入口
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "dist"), // 路径必须是一个绝对路径
  },
  // 数组 放着所有的webpack插件
  plugins: [
    new DllReferencePlugin({
      manifest: path.resolve(__dirname, "dist", "manifest.json"),
    }),
    new HtmlWebpackPlugin({
      template: "./src/index.html", // 模板
      filename: "index.html", // 文件名
    }),
    new MiniCssExtractPlugin({
      filename: "css/main.css",
    }),
  ],
  // 模块
  module: {
    // 规则
    rules: [
      {
        test: /\.js$/, // normal 普通的loader
        use: {
          // babel-loader 将ES6转ES5
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env", "@babel/preset-react"],
          },
        },
        include: path.resolve(__dirname, "src"),
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
      },
    ],
  },
};
